﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MusicDatabase
{
    /*
     * Auteur:  Joris Molnár en Niels van Leusden
     * Datum:   31-1-2013
     * Omschrijving: Deze klasse vult het scherm ArtistInfo met alle informatie over de geselecteerde artiest.
     * 
     */
    public partial class ArtistInfo : Form
    {
        public ArtistInfo(int artistID, string artistName)
        {
            InitializeComponent();
            FillSongs(artistID);
            Artistname(artistName);
            FillFields(artistID);
        }

        private void Artistname(string artistname)
        {
            lblName.Text = artistname;
        }

        /// <summary>
        /// Fill the DGV with songs
        /// </summary>
        /// <param name="artistID"></param>
        private void FillSongs(int artistID)
        {
            SQLServices sqlService = new SQLServices();

            string command = "SELECT song_name Song, album.alb_name Album, genre_name Genre, CONVERT(nvarchar, song.song_length/60) + ':' + CASE WHEN song.song_length%60<10 THEN '0' + CONVERT(nvarchar, song.song_length%60) ELSE CONVERT(nvarchar, song.song_length%60) END Length, song_date Date " +
                "FROM song, genre, artist, album, songrelease " +
                "WHERE song.song_id = songrelease.song_id AND album.alb_id = songrelease.alb_id AND genre.genre_id = song_genre AND song.art_id = artist.art_id AND song.art_id = " + artistID +
                " ORDER BY song_name";

            List<string[]> content = sqlService.GetTable(command);

            for (int i = 0; i < content[0].Length; i++) // Fill the DGV
            {
                dgvSongs.Columns.Add(content[0][i], content[0][i]);
            }
            for (int i = 1; i < content.Count; i++)
            {
                dgvSongs.Rows.Add(content[i]);
            }
            dgvSongs.Columns[0].Width = 185;
            dgvSongs.Columns[1].Width = 190;                
            dgvSongs.Columns[2].Width = 75;
            dgvSongs.Columns[3].Width = 50;
            dgvSongs.Columns[4].Width = 50;
        }

        /// <summary>
        /// Fill the Fields
        /// </summary>
        /// <param name="artistID"></param>
        private void FillFields(int artistID)
        {
            SQLServices sqlService = new SQLServices();

            string command = "SELECT art_formed_date, art_formed_country, art_notes, art_biography FROM artist WHERE art_id = " + artistID;
            lblCountry.Text = Convert.ToString(sqlService.GetTable(command)[1][1]);
            lblDate.Text = Convert.ToString(sqlService.GetTable(command)[1][0]);
            lblNotes.Text = Convert.ToString(sqlService.GetTable(command)[1][2]);
            lblBiography.Text = Convert.ToString(sqlService.GetTable(command)[1][3]);
        }
    }
}
